<?php

class Tyh_Error
{
	private static $instance;
	
	public function __construct()
	{
		$this->tyh = tyh_get_instance();
	}
	
	public function is_debug_on() 
	{
		if( WP_DEBUG && $this->tyh->config->tyh_debug )
		{
			return TRUE;
		}

		return FALSE;
	}
	
	/*
	 * Show error message only when debugging is enabled.
	 * 
	 * @param error_msg The error message
	 * @param content Defines where the error originated
	 * @param error_type PHP error levels, like E_USER_NOTICE
	 * 
	 * return bool FALSE
	 */
	public function trigger( $error_msg, $context = '', $error_type = E_USER_NOTICE )
	{
		if( $this->is_debug_on() )
		{
			$error_msg = $error_msg . ' Context: ' . $context;
			trigger_error($error_msg, $error_type);
		}
		
		return FALSE;		
	}
	
	public static function getInstance()
	{		
		if( !isset(self::$instance) )
		{
			self::$instance = new self();
		}
		
		return self::$instance;
	}	
}